﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Biblioteca.fachada;
using Biblioteca.classesBasicas.equipamento;

namespace Desktop.views.cruds.crudsEquipamento.crudArma
{
    public partial class MenuArma : Form
    {
        private MenuEquipamento menuEquipamento;
        private Fachada fachada = new Fachada();
        private List<Arma> listaArmas;
        private Arma arma = new Arma();
        

        public MenuArma(MenuEquipamento menuEquipamento)
        {
       
            this.menuEquipamento = menuEquipamento;
            menuEquipamento.Hide();

            InitializeComponent();
        }

        private void buttonCadastrar_Click(object sender, EventArgs e)
        {
            CadastroArma cadastroArma = new CadastroArma(this);
            cadastroArma.ShowDialog();
        }

        private void buttonSair_Click(object sender, EventArgs e)
        {
            menuEquipamento.Show();
            this.Dispose();
        }

        private void MenuArma_FormClosed(object sender, FormClosedEventArgs e)
        {
            menuEquipamento.Show();
            this.Dispose();
        }

        private void MenuArma_Load(object sender, EventArgs e)
        {
            this.carregarGridViewArma();
        }

        private void dataGridViewArma_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1)
            {
                DataGridViewRow row = this.dataGridViewArma.Rows[e.RowIndex];

                arma.Id = row.Cells[0].Value.ToString();
                arma.Nome = row.Cells[1].Value.ToString();
                arma.Tipo = row.Cells[2].Value.ToString();
                arma.Marca = row.Cells[3].Value.ToString();
                arma.Valor = row.Cells[4].Value.ToString();

                AlterarRemoverArma alterar = new AlterarRemoverArma(this, arma);
                alterar.ShowDialog();
            }
        }


        public void carregarGridViewArma()
        {
            listaArmas = fachada.listarArma();

            DataGridViewCellStyle columnHeaderStyle =
            new DataGridViewCellStyle();
            columnHeaderStyle.BackColor = Color.Aqua;
            columnHeaderStyle.Font =
                new Font("Verdana", 10, FontStyle.Bold);
            this.dataGridViewArma.ColumnHeadersDefaultCellStyle =
                columnHeaderStyle;

            dataGridViewArma.DataSource = listaArmas;

            this.dataGridViewArma.Columns[0].HeaderText = "ID";
            this.dataGridViewArma.Columns[1].HeaderText = "NOME";
            this.dataGridViewArma.Columns[2].HeaderText = "TIPO";
            this.dataGridViewArma.Columns[3].HeaderText = "MARCA";
            this.dataGridViewArma.Columns[4].HeaderText = "VALOR";
        }
        
    }
}
